<template>
  <base-breadcrumb :title="titleName">
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-card :bordered="false">
      <!-- <title-name title="施工进度总计划调整列表" /> -->
      <div
        class="table-operator"
        style="margin-top:10px"
      >
        <a-button
          v-btnPermission="'pm_014_add_01'"
          type="primary"
          @click="handleAdd('add')"
        >
          新增调整
        </a-button>
        <a-button
          v-btnPermission="'pm_014_per_10'"
          type="primary"
          @click="visibleState.isSet = true"
        >
          信息调整权限设置
        </a-button>
      </div>
      <div class="pub-table-select-count">
        <a-icon
          type="info-circle"
          theme="twoTone"
        />
        <span style="margin-right: 12px">
          施工进度总计划调整：<span class="totalNum">{{ totalSize }} </span> |
          待提交审核：<span class="totalNum">{{ total.draftNum|| 0 }} 项 </span> |
          审核中：<span class="totalNum">{{ total.auditNum|| 0 }} 项 </span> |
          审核通过：<span class="totalNum">{{ total.passNum || 0 }} 项 </span> |
          审核不通过：<span class="totalNum">{{ total.noPassNum || 0 }} 项 </span> |
          待调整：<span class="totalNum">{{ total.toBeAdjusted || 0 }} 项 </span>
        </span>
      </div>
      <s-table
        ref="table"
        :scroll="{ x: 1000 }"
        size="default"
        row-key="key"
        :columns="columns"
        :data="loadData"
        :alert="true"
        show-size-changer
        show-quick-jumper
        show-pagination="auto"
      >
        <span
          slot="serial"
          slot-scope="text, record, index"
        >{{ index + 1 }}</span>
        <span
          slot="status"
          slot-scope="text"
        >
          <a-badge
            :status="text | statusTypeFilter"
            :text="text | statusFilter"
          />
        </span>
        <span
          slot="action"
          slot-scope="text, record"
        >
          <template>
            <!-- 查看 -->
            <a
              v-btnPermission="'pm_014_loo_02'"
              @click="handleSub(record,'view')"
            >查看</a>
            <!-- 编辑 -->
            <a-divider
              v-if="record.statusCode=='0' || record.statusCode=='3'"
              v-btnPermission="'pm_014_edi_03'"
              type="vertical"
            />
            <a
              v-if="record.statusCode=='0' || record.statusCode=='3'"
              v-btnPermission="'pm_014_edi_03'"
              @click="handleAdjustEdit(record,'edit')"
            >编辑</a>
            <!-- 删除 -->
            <a-divider
              v-if="record.statusCode=='0' || record.statusCode=='3'"
              type="vertical"
            />
            <a
              v-if="record.statusCode=='0' || record.statusCode=='3'"
              @click="handledelete(record)"
            >删除</a>
            <!-- 一级节点调整中 -->
            <a-divider
              v-if="record.statusCode=='4'"
              type="vertical"
            />
            <a
              v-if="record.statusCode=='4'"
              v-btnPermission="'pm_014_one_04'"
              @click="adjustFirstNode(record)"
            > 一级调整 </a>
            <!-- 二级节点调整中 -->
            <a-divider
              v-if="record.statusCode=='5'"
              type="vertical"
            />
            <a
              v-if="record.statusCode=='5'"
              v-btnPermission="'pm_014_two_05'"
              @click="adjustSecondNode(record)"
            > 二级调整 </a>
            <!-- 三级节点调整中 -->
            <a-divider
              v-if="record.statusCode=='6'"
              type="vertical"
            />
            <a
              v-if="record.statusCode=='6'"
              v-btnPermission="'pm_014_thr_06'"
              @click="adjustThirdNode(record)"
            > 三级调整 </a>
            <!-- 跟踪审批流程 -->
            <!-- <approval-button  :status="record.statusCode" :id="record.planId" v-btnPermission="'pm_014_moi_05'"></approval-button> -->
            <a-divider
              v-if="record.statusCode=='1' || record.statusCode=='3'"
              v-btnPermission="'pm_014_moi_08'"
              type="vertical"
            />
            <a
              v-if="record.statusCode=='1' || record.statusCode=='3'"
              v-btnPermission="'pm_014_moi_08'"
              @click="handleApproveDetail(record)"
            >审批信息</a>
          </template>
        </span>
      </s-table>    
      <!-- 审批详情 -->
      <ApprovalDetails
        :title="'审批详情'"
        :business-id="businessId"
        :visible="visibleApprove"
        @cancel="visibleApprove = false"
        @confirm="visibleApprove = false"
      />
    </a-card>
    <SetEditProject :visible.sync="visibleState.isSet" />
  </base-breadcrumb>
</template>

<script>
  import moment from 'moment'
  import { STable } from '@/components'
  import { getConstructionAdjustList,getConstructionAdjustListStatistics ,deleteAdjust } from '@/api/adjust'

  import ApprovalDetails from '@/components/approvalDetails'
  import SetEditProject from './SetEditProject'

 const columns = [
    {
      title: '序号',
      width:65,
      scopedSlots: { customRender: 'serial' }
    },
    {
      title: '项目名称',
      dataIndex: 'projectName'
    },
    {
      title: '调整一级节点个数',
      dataIndex: 'adjustFirstNodeNum',
    },
    {
      title: '调整二级节点个数',
      dataIndex: 'adjustSecondNodeNum',
    },
    {
      title: '调整三级节点个数',
      dataIndex: 'adjustThirdNodeNum',
    },
    {
      title: '创建时间',
      dataIndex: 'createTime',
    },
    {
      title: '申请人 ',
      dataIndex: 'applicat',
    },
    {
      title: '状态 ',
      dataIndex: 'status',
    },
    {
      title: '操作',
      dataIndex: 'action',
      width: '180px',
      scopedSlots: { customRender: 'action' }
    }
  ]
 const searchArr =[
    // 搜索框
    // {
    //   name: '业务事项',
    //   value: 'businessMatters',
    //   type: 'input'
    // },
    {
      name: '项目名称',
      value: 'projectName',
      type: 'input',
    },
    // {
    //   name: '阶段/类型',
    //   value: 'stageType',
    //   type: 'input',
    // },
    // {
    //   name: '节点等级',
    //   value: 'nodeLevel',
    //   type: 'select',
    //   data:[
    //     {
    //       value: '1',
    //       label: '一级节点'
    //     },
    //     {
    //       value: '2',
    //       label: '二级节点'
    //     },
    //     {
    //       value: '3',
    //       label: '三级节点'
    //     }
    //   ]
    // },
    {
      name: '状态',
      value: 'status',
      type: 'select',
      data:[
        {
          value: '0',
          label: '待提交审核'
        },
        {
          value: '1',
          label: '审核中'
        },
        {
          value: '2',
          label: '审核不通过'
        },
        {
          value: '3',
          label: '一级调整中'
        },
        {
          value: '4',
          label: '二级调整中'
        },
        {
          value: '5',
          label: '三级调整中'
        },
        {
          value: '6',
          label: '调整完成'
        },
      ]
    },
  ]
  export default {
    name:'a'+Date.now(),
    components: {
      STable,
      ApprovalDetails,
      SetEditProject,
    },
    data() {
      this.columns = columns
      this.searchArr = searchArr
      return{
        visibleState: {
          isSet: false,
        },
        titleName:'',
        form:{
          projectName:'',
          projectFormat:''
        },
        statistics:[],
        // create model
        visible: false,
        confirmLoading: false,
        mdl: null,
        // 高级搜索 展开/关闭
        advanced: false,
        // 查询参数
        queryParam: {},
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          const requestParameters = Object.assign({}, parameter, this.queryParam)
          //   console.log('loadData request parameters:', requestParameters)
          return getConstructionAdjustList(requestParameters).then(res => {
            console.log('数据返回对象：', res)
            this.totalSize = res.totalSize
            return res
          })
        },
        selectedRowKeys: [],
        selectedRows: [],
        company:[],
        addVisible:false,
        total:{},
        totalSize:'',
        businessId:'',
        visibleApprove:false,
      }
    },
    created() {
      this.getStatistics()
    },
    computed: {
      // rowSelection() {
      //   return {
      //     selectedRowKeys: this.selectedRowKeys,
      //     selectedRows: this.selectedRows,   // 当前行所有数据
      //     onChange: this.onSelectChange
      //   }
      // }
    },
    methods: {
      handleAdjustEdit(record,type){
        console.log(record.planId)
        this.$router.push({
          path:'/construction/addAdjustEdit',
          query:{
            id:record.planId,
            type:type
          }
        })
      },
      handledelete(record){
        let _this = this
        this.$confirm({
          title: '警告提醒！',
          content: '是否删除当前数据？',
          okType: 'danger',
          onOk() {
            return new Promise((re,rj)=>{
              deleteAdjust({id:record.planId}).then((res)=>{
                if(res.code='200'){
                  _this.$message.success("删除成功")
                  _this.search()
                }
                re()
              }).catch(()=>rj)
            })

          },
          onCancel() {
            _this.$message.error("删除失败")
          }
        })
      },
      handleAdjust(value){
        console.log(value)
        this.$router.push({
          path:'/project/firstNodeAdjust' ,
          query:{
            id:value.planId
          }
        })
      },
      handleApproveDetail(record){
        this.visibleApprove = true
        this.businessId = record.planId
      },
      search(values){
        this.queryParam = values
        this.$refs.table.refresh(true)
        this.getStatistics()
      },
      getStatistics(){
        getConstructionAdjustListStatistics(this.queryParam).then((res)=>{
          this.total = res.data
          console.log(this.statistics)
        })
      },
      handleSub(record,type){
        this.$router.push({
          path:'/construction/addAdjustView',
          query:{
            id:record.planId,
            type:type
          }
        })
      },
      handleAdd(){
        this.$router.push({
          path:"/construction/addAdjust",
          query:{
            type:'add'
          }
        })
      },
      handleCancel(){
        this.addVisible = false
      },
      searchData(){   // 搜索
        this.$refs.table.refresh(true)
      },
      onSelectChange(selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      toggleAdvanced() {
        this.advanced = !this.advanced
      },
      adjustFirstNode(record){
        this.$router.push({
          path:"/project/firstNodeAdjust",
          query:{
            id:record.planId,
            type:record.statusCode
          }
          })
      },
      adjustSecondNode(record){
        this.$router.push({
          path:"/project/secondNodeAdjust",
          query:{
            id:record.planId,
            type:record.statusCode
          }
          })
      },
      adjustThirdNode(record){
        this.$router.push({
          path:"/project/thirdNodeAdjust",
          query:{
            id:record.planId,
            type:record.statusCode
          }
          })
      },
      resetSearchForm() {
        this.queryParam = {
          date: moment(new Date())
        }
      }
    }
  }
</script>
<style scoped>
    .ant-modal-body{
        padding:0
    }
    .icon{
        transform: rotate(90deg);
        color:#349ED8
    }
</style>
